Overview

J-Term Pro provides you with some of the most powerful scripting available in any telnet client.  The J-Term Pro scripting language is a subset of the Pascal programming language, with special enhancements for performing tasks such as opening and closing connections, using FTP from a script, and capturing text coming from the remote host. This help file is designed to give you enough of an introduction to scripting with J-Term Pro to get you started writing your own scripts. A good text on the Pascal language might be helpful, too.

The following script rules apply:

All J-Term Pro script blocks begin with the word begin and end with the word end.

All script statements should be followed with a semi-colon (;).

Any variables your script uses should be declared outside the begin..end; block.

Comments can be enclosed in curly braces {}, or anything after two slashes ( // ) on a line is considered a comment.

J-Term Pro is case insensitive. ABC = aBc = abc. Literal strings are case sensitive.

Below is a very simple script to show the format of a typical J-Term Pro script. Try typing it in the script manager and running it now.

// Script to get a user's name

var Name: String;   // Variable to hold the name

begin

  Name:=InputBox('Getting user name','Please enter your name','');

  ShowMessage('Hello, '+Name);

end;


Data Types and Variables

J-Term Pro has the ability for your script to use variables for holding values of data. These variables can be any one of six basic types:

•	Integer - Integer variables hold whole numbers in the range –32768..32767

•	LongInt - LongInt variables hold whole numbers in the range -2147483648..2147483647

•	Real - Real variables hold real numbers in the range

•	String – String variables hold text strings, like file names, or machine names. Literal strings in J-Term Pro are surrounded by single quotes.

•	Char – Char variables hold a single character. Literal characters in J-Term Pro are surrounded by single quotes.

•	Boolean – Boolean values hold one of two values, true or false.

As mentioned before, variables are used to hold data values. To declare a variable for use in your script, use the following syntax:

var VarName: VarType;

The reserved word 'var' need only be used once in any variable block declaration. Multiple variables of the same type can be declared together, with a comma separating the names. Variable names are composed of combinations of uppercase and lowercase letters. Here are some sample variable declarations in J-Term Pro:

var X, Y, Z: Integer;

    Name, Address: String;

    Income: Real;

    Status: Char;


Assignment Statements

Variables in J-Term Pro are assigned values with assignment statements. Assignment statements take the following form:

VarName:=Expression;

Where 'Expression' is a valid value or mathematical expression. Here are some examples, in a sample script:

var MyInt: Integer;

    MyStr: String;

    MyBoolean: Boolean;

    MyReal: Real;

    MyChar: Char;

    MyLongInt: LongInt;

begin

  MyInt:=5;

  MyStr:='J-Term Pro scripting is great!';

  MyBoolean:=True;

  MyReal:=4.756 + 2.345;

  MyChar:='A';

  MyLongInt:=MyInt*5;   // Would yield 5*5 or 25 as the value

end;

A variable can also be assigned the return value of a J-Term Pro function. For example (using the variables from above):

MyStr:=InputBox('Getting user name','Please enter your name','');

places the return value of the InputBox function (a string) into the MyStr variable. See the section on functions for a fuller explanation of function return values.


Data Conversion Functions

The following functions are used to convert from one data type to another. Click on the individual function to see its help.

IntToStr

StrToInt

FloatToStr

StrToFloat


IntToStr

function IntToStr(IntValue:Integer): String;

The IntToStr function is used to convert an integer value to a string value.

var MyStr: String;

    MyInt: Integer;

begin

  MyInt:=5;

  MyStr:=IntToStr(MyInt);

  MyStr:=IntToStr(3);

end;


StrToInt

function StrToInt(StrValue:String): Integer;

The StrToInt function is used to convert a string value to an integer value.

var MyStr: String;

    MyInt: Integer;

begin

  MyInt:=StrToInt('1234');

  MyStr:='556';

  MyInt:=StrToInt(MyStr);

end;

* Note – a string value as the argument to this function that is not a valid integer will yield an error.


FloatToStr

function FloatToStr(RealValue:Real): String;

The FloatToStr function is used to convert a real value to a string value.

var MyReal: Real;

begin

  MyReal:=123.456;

  ShowMessage(FloatToStr(MyReal));

end;


StrToFloat

function StrToFloat(StrValue:String): Real;

The StrToFloat function is used to convert a string value to a real value.

var MyString: String;

begin

  MyString:='123.456';

  MyReal:=StrToFloat(MyString);

  MyReal:=StrToFloat('54.56');

end;

* Note - a string value as the argument to this function that is not a valid real will yield an error.


String Manipulation

The following routines can be used in your J-Term Pro scripts to manipulate string variables, adding lots of power and flexibility to your scripts. To see the individual help on a procedure or function, click on it.

Length

Pos

Copy

Insert

Delete

UpperCase

LowerCase

Concatenation

Control characters


Length

function Length(StrValue:String): Integer;

The length function returns the length, in characters, of the given string.

var MyInt: Integer;

begin

  MyInt:=Length('J-Term Pro scripting');

end;


Pos

function Pos(SubStr, StrValue:String): Integer;

The Pos function returns the position of the string SubStr in the string StrValue. The position is returned as an integer representing the offset from the beginning of StrValue where SubStr is located.

var MyPos: Integer;

begin

  MyPos:=Pos('erm','J-Term Pro');

  // MyPos is 4, because 'erm' starts at position 4 in 'J-Term Pro'

end;


Copy

function Copy(StrValue:String; Start,Count:Integer): String;

The Copy function copies Count characters from the Start position in StrValue. The function returns the copied substring as a result.

var MyStr: String;

begin

  MyStr:=Copy('J-Term Pro',3,4);

  // MyStr is now 'Term'  - Copy copied the four characters starting

  // from position three

end;


Insert

procedure Insert(Str1:String; var Str2:String; Index:Integer);

The Insert procedure inserts Str1 into Str2 at position Index.

var Str: String;

begin

  Str:='J-Term Pro scripting';

  Insert('does ',Str,12);

  // Str is now 'J-Term Pro does scripting'

end;


Delete

procedure Delete(var Str:String; Start,Count:Integer);

The Delete procedure deletes Count characters from Str starting at position Start.

var Str: String;

begin

  Str:='J-Term Pro does scripting';

  Delete(Str,12,5);

  // Str is now 'J-Term Pro scripting'

end;


UpperCase

function UpperCase(S:String): String;

The UpperCase function returns the upper-case equivalent of the string passed to it in the S parameter.

begin

  ShowMessage(UpperCase('J-Term Pro'));

end;


LowerCase

function Lowercase(S:String): String;

The LowerCase function returns the lower-case equivalent of the S parameter.

begin

  ShowMessage(LowerCase('J-Term Pro'));

end;


Concatenation

You can concatenate two strings by using the addition operator (+).

var S: String;

begin

  S:='J-Term'+' '+'Pro';

  // S = 'J-Term Pro' now

end;


Control Characters

You can use any control character in a string (or any ASCII character, for that matter) by using the pound sign (#) followed by the ASCII number for a character. Control characters are #1 (CTRL-A) through #26 (CTRL-Z). They can be treated as any other string.

begin

  // Send some text followed by a CTRL-D to the active page

  SendText(ActivePage,'This is a test'+#4);

end;


Loop Control

In J-Term Pro scripting, loops are used when you need to perform a specific action or series of actions more than one time. J-Term Pro has three different kinds of loops, listed below. For more information, click on the loop type.

For loops

While loops

Repeat loops


For loops

for LoopVar:=StartVal to|downto EndVal do statement;

The for loop counts from StartVal to EndVal by 1, executing statement each time. LoopVar, StartVal, and EndVal are all integers or longints. To count backwards, use downto. If statement needs to be a block of statements, surround the block with begin..end;

var X: Integer;

    Str: String;

begin

  for X:=1 to 5 do

    ShowMessage(IntToStr(X));

  Str:='';

  for X:=5 downto 1 do

  begin

    Str:=Str+IntToStr(X);

    ShowMessage(Str);

  end;

  // Str is now '54321'

end;


While loops

while condition do statement;

The while loop executes statement as long as condition is true. If statement needs to be a block of statements, surround the block with begin..end;

var X, Y: Integer;

begin

  X:=1;

  Y:=0;

  while X<100 do

  begin

    Y:=Y+X;

    X:=X+1;

  end;

  ShowMessage(IntToStr(Y));

  // Y is the sum of all the numbers from 1 to 100

end;


Repeat loops

repeat statement until condition;

The repeat loop repeats statement until condition is true. statement can be a block of statements without the necessity of a begin..end.

var X, Y: Integer;

begin

  X:=1;

  Y:=0;

  repeat

    Y:=Y+X;

    X:=X+1;

  until X=101;

  // Y is the sum of the integers from 1 to 100

end;


Conditional Statements

The if statement

if condition then statement1

[ else statement2 ];

The if statement is used to test one or more conditions and perform statement1 if that/those conditions are true. If you are testing multiple conditions, each condition must be in a set of parentheses, and the conditions must be separated by reserved words and or or.

If you use the optional else, then statement2 is performed if condition is false. Additionally, if you use an else, statement1 must not have a semi-colon at the end.

Valid comparison operators for conditions are:

•	= - equal to

•	< - less than

•	> - greater than

•	<> - not equal to

•	<= - less than or equal to

•	>= - greater than or equal to

•	not – for Boolean types only. (not true) = false, and (not false) = true

var Age, Loop: Integer;

    AgeStr: String;

    IsValid: Boolean;

    AgeChar: Char;

begin

  IsValid:=False;

  while (not IsValid) do // Make sure they enter a valid number

  begin

    AgeStr:=InputBox('Getting age','Please enter your age','');

     IsValid:=True;

    for Loop:=1 to Length(AgeStr) do

    begin

      AgeChar:=Copy(AgeStr,Loop,1);

      // Check to make sure each char is a valid number

      if (AgeChar<'0') or (AgeChar>'9') then

        IsValid:=False;

    end;

    if (not IsValid) then

      ShowMessage('Sorry, '+AgeStr+

                  ' is not a valid number. Please try again.');

  end;

  Age:=StrToInt(AgeStr);

  if (Age<21) then ShowMessage('Still a kid.')

  else if (Age<40) then ShowMessage('Wet behind the ears')

  else if (Age<65) then ShowMessage('Middle aged')

  else ShowMessage('Would you like a 10% discount?');

end;


Input and Output

J-Term Pro provides many routines to get input from the user, and to give output back to the user. Individual routines are listed below. To get help on any routine, just click on it.

InputBox

InputQuery

GetUserPass

GetScreenText

ChooseFileOpen

ChooseFileSave

ShowMessage

WriteStatus

ClearStatus

StartFileLog

StopFileLog

ShowMessageWindow

HideMessageWindow

SetMessageWindowText


InputQuery

function InputQuery(Caption, Prompt: String; var Value:String): Boolean;

The InputQuery function displays a dialog that allows the user to enter a string. Caption is used as the caption for the dialog. Prompt is used as a string prompt, and Value is a variable to hold the value of the string entered. You can set Value to some default string before you call InputQuery. The function returns True if  the user clicks the Ok button, and False otherwise.

var Name: String;

begin

  Name:='Bubba';

  if (InputQuery('Getting name','Please enter your name',Name)) then

    ShowMessage('Hello, '+Name);

end;


GetUserPass

function GetUserPass(var User, Pass:String; Caption:String): Boolean;

The GetUserPass function opens a dialog prompting the user to enter a username and password. The password is masked by asterisks, so it can't be read from the screen. Caption is used as the caption for the dialog. The function returns True if the user clicks 'Ok' and False if the user clicks 'Cancel'. If the User parameter is not an empty string, GetUserPass populates the 'User name' entry in the dialog with that value and sets the focus of the dialog to the 'Password' entry edit.

var UserName, Password: String;

begin

  GetUserPass(UserName,Password,'Enter account info');

end;


GetScreenText

function GetScreenText(PageNo, StartRow, StartCol, StopRow, StopCol:

                       Integer): String;

The GetScreenText returns a string containing the screen text inside the box defined by the start/stop rows and columns. The rows and columns are zero-based, meaning row numbers go from 0 to 24 or 49 and columns are from 0 to 79 or 131, depending on your connection configuration.

var X: String;

begin

  // Grab the whole screen

  X:=GetScreenText(ActivePage,0,0,10,79);

  // Display the 3rd line

  ShowMessage(Copy(X,(80*2)+1,80));

end;


ChooseFileOpen

function ChooseFileOpen(InitialDir,Filter:String):String;

The ChooseFileOpen function opens a standard windows 'File open' dialog for a user to choose a file name. InitialDir tells the dialog the directory in which to initially start. Filter gives a list of standard file filters for giving the user choices about what types to display. Filter entries are shown in the 'Files of type' combo box in the dialog, and give the user a way do easily filter files by a particular extension. Each filter has a description, and filter entries are separated by a vertical bar '|'. For example, a filter of 'J-Term Pro script files|*.jts' would default the dialog to showing only J-Term Pro script files. You can add as many filters as you want by separating them with a vertical bar.

The return value of the function is the filename selected.

begin

  // Look in C:\TMP for a file

  // Default to *.jts files, but allow a *.* filter, also

  ChooseFileOpen('C:\TMP','JTP script files|*.JTS|All files|*.*');

end;


ChooseFileSave

function ChooseFileSave(InitialDir,Filter:String):String;

The ChooseFileSave function opens a standard windows 'File save' dialog for a user to choose a file name. InitialDir tells the dialog the directory in which to initially start. Filter gives a list of standard file filters for giving the user choices about what types to display. Filter entries are shown in the 'Files of type' combo box in the dialog, and give the user a way do easily filter files by a particular extension. Each filter has a description, and filter entries are separated by a vertical bar '|'. For example, a filter of 'J-Term Pro script files|*.jts' would default the dialog to showing only J-Term Pro script files. You can add as many filters as you want by separating them with a vertical bar.

The return value of the function is the filename selected.

begin

  // Look in C:\TMP for a file

  // Default to *.jts files, but allow a *.* filter, also

  ChooseFileSave('C:\TMP','JTP script files|*.JTS|All files|*.*');

end;


ShowMessage

procedure ShowMessage(Msg:String);

The ShowMessage procedure displays a dialog box with Msg inside it. The user can click the Ok button to dismiss the dialog.

var Name: String;

begin

  Name:=InputBox('Getting name','Please enter your name','');

  if (Name<>'') then ShowMessage('Hello, '+Name);

end;


InputBox

function InputBox(Caption,Prompt,Default:String): String;

The InputBox function displays a dialog that allows the user to enter a string. Caption is used as the caption for the dialog, Prompt is used as a string prompt, and Default is a default value for the string entered. The function returns the string entered as it's value.

var Name: String;

begin

  Name:=InputBox('Getting name','Please enter your name','');

  if (Name<>'') then ShowMessage('Hello, '+Name);

end;


WriteStatus

procedure WriteStatus(Msg:String);

The WriteStatus procedure writes Msg to the J-Term Pro status bar.

var Name: String;

begin

  Name:=InputBox('Getting name','Please enter your name','');

  if (Name<>'') then WriteStatus('Hello, '+Name);

end;


ClearStatus

procedure ClearStatus;

The ClearStatus procedure clears the J-Term Pro status bar of any messages.

begin

  ClearStatus;

end;


StopFileLog

procedure StopFileLog(PageNo:Integer);

The StopFileLog procedure turns off data logging to a file for the specifics connection.

 begin

  StopFileLog(ActivePage);

end;


StartFileLog

procedure StartFileLog(PageNo:Integer; FileName:String);

The StartFileLog procedure turns on file logging for the specified open connection (PageNo). The data sent to and received from the session is stored in the file specified by the FileName parameter. The logging can be stopped by closing the connection, clicking 'Log to file' on the Tools menu, or by calling the StopFileLog procedure.

var PN: Integer;

begin

  PN:=OpenConnection('JAI Linux');

  StartFileLog(PN,'C:\TMP\JAI.LOG');

end;


File Manipulation

J-Term Pro provides a rich set of routines for manipulating files. These routines are listed below, and you can get help on any one by clicking on it.

FileCreate

FileOpen

FileClose

FileRead

FileWrite

FileExists

FileSeek

FileCopy

FileMove

FileDelete

FileRename

ChooseFileOpen

ChooseFileSave


FileCreate

function FileCreate(FileName:String): Integer;

The FileCreate function creates an empty file with the name FileName on your hard drive. The return value of FileCreate is an integer handle to the newly created file. This handle can be used in the FileRead, FileWrite, and FileClose routines. FileCreate will return a –1 if the specified file could not be created. The FileName can include an absolute path.

var FileDes: Integer;

begin

  FileDes:=FileCreate('C:\TMP\TEST.TXT');

  if (FileDes>=0) then

  begin

    FileWrite(FileDes,'J-Term Pro',10);

    FileClose(FileDes);

  end;

end;


FileOpen

function FileOpen(FileName:String; Mode:Integer): Integer;

The FileOpen function opens the file named FileName on your hard drive. The return value of FileOpen is an integer handle to the newly opened file. This handle can be used in the FileRead, FileWrite, and FileClose routines. The Mode of the file tells how the file will be used, and can be fmOpenRead, fmOpenWrite, or fmOpenReadWrite. FileOpen will return a –1 if the specified file could not be opened (for example, if it doesn't exist). The FileName can include an absolute path.

var FileDes: Integer;

    Data: String;

begin

  FileDes:=FileOpen('C:\TMP\TEST.TXT',fmOpenRead);

  if (FileDes>=0) then

  begin

    FileRead(FileDes,Data,255);

    FileClose(FileDes);

    ShowMessage(Data);

  end;

end;


FileClose

procedure FileClose(FileDes:Integer);

The FileClose procedure will close the open file specified by FileDes. See the help for FileOpen or FileCreate for an example of using this procedure.


FileRead

function FileRead(FileDes:Integer; var Data:String;

                  BytesToRead:Integer): Integer;

The FileRead function attempts to read BytesToRead bytes into Data from the open file specified by FileDes. The file must have previously been opened with mode fmOpenRead or fmOpenReadWrite. The function returns the number of bytes actually read.

var FileDes: Integer;

    Data: String;

begin

  FileDes:=FileOpen('C:\TMP\TEST.TXT',fmOpenRead);

  if (FileDes>=0) then

  begin

    FileRead(FileDes,Data,255);

    FileClose(FileDes);

    ShowMessage(Data);

  end;

end;


FileWrite

function FileWrite(FileDes:Integer; Data:String;

                   BytesToWrite:Integer): Integer;

The FileWrite function attempts to write BytesToWrite bytes from Data into the open file specified by FileDes. . The file must have previously been opened with mode fmOpenWrite or fmOpenReadWrite. The function returns the number of bytes actually written.

var FileDes: Integer;

begin

  FileDes:=FileCreate('C:\TMP\TEST.TXT');

  if (FileDes>=0) then

  begin

    FileWrite(FileDes,'J-Term Pro',10);

    FileClose(FileDes);

  end;

end;


FileExists

function FileExists(FileName:String): Boolean;

The FileExists function returns True if the file specified by FileName exists on the hard drive; otherwise, it returns False. An absolute path can precede the absolute file name.

begin

  if (FileExists('C:\CONFIG.SYS')) then

    ShowMessage('You have a CONFIG.SYS file')

  else ShowMessage('You do NOT have a CONFIG.SYS file');

end;


FileSeek

function FileSeek(FileDes, Offset, Origin: Integer): Integer;

The FileSeek function seeks to position Offset relative to position Origin in the open file specified by FileDes. Origin can have these possible values:

0	Seek from beginning of file

1	Seek from current position

2	Seek from end of file

FileSeek returns a –1 if it cannot successfully perform the seek, or the new file pointer position (as an offset from the beginning of the file) if it is successful.

var FD: Integer;

    S: String;

begin

  FD:=FileOpen('C:\TMP\FRED.LOG',fmOpenRead);

  if (FD>0) then

  begin

    { Position ourselves 100 bytes from the end of the file }

    FileSeek(FD,-100,2);

    { Read the last 10 bytes of the file }

    FileRead(FD,S,100);

    ShowMessage(S);

    { Go to position 350 in the file and read 10 bytes }

    FileSeek(FD,350,0);

    FileRead(FD,S,10);

    ShowMessage(S);

    FileClose(FD);

  end

  else ShowMessage('Could not open file');

end;


FileCopy

function FileCopy(From,To:String): Boolean;

The FileCopy function copies the file in From to the file in To, returning a true if the copy was successful, and a false if it was not. Both From and To can contain a complete path.

begin

  // Make a backup of AUTOEXEC.BAT

  FileCopy('C:\AUTOEXEC.BAT','C:\AUTOEXEC.BAK');

end;


FileMove

function FileMove(From,To:String): Boolean;

The FileMove function moves the file in From to the file in To, returning a true if the move was successful, and a false if it was not. Both From and To can contain a complete path.

begin

  // Move an old log file

  FileMove('C:\TMP\FRED.LOG','LAST.LOG');

end;


FileRename

function FileRename(From,To:String): Boolean;

The FileRename function renames the file in From to the file in To, returning a true if the rename was successful, and a false if it was not. Both From and To can contain a complete path.

begin

  // Rename an old log file

  FileRename('FRED.LOG','FRED.OLD');

end;


FileDelete

function FileDelete(FileName:String): Boolean;

The FileDelete function deletes the file in FileName, returning a true if the deletion was successful, and a false if it was not. FileName can contain a complete path.

begin

  // Delete an old log file

  FileDelete('C:\TMP\FRED.LOG');

end;


FileSize

function FileSize(FileName:String): LongInt;

The FileSize function returns the size, in bytes, of the file specified by FileName. FileName can contain a complete path.

var X: LongInt;

begin

  // Find the size of AUTOEXEC.BAT

  X:=FileSize('C:\AUTOEXEC.BAT');

  ShowMessage('Autoexec is '+IntToStr(X)+' bytes.');

end;


Writing Procedures and Functions

J-Term Pro scripting provides the means for you to write your own procedures and functions for your scripts, because sometimes scripts get too long and cumbersome to have everything in one big begin..end block. The following rules apply when writing procedures and functions:

•	Procedure and function names can be any combination of upper and lower case letters

•	All procedures and functions must be defined above the main begin..end block of the script.

•	Variables declared inside a procedure or function are local to that procedure or function only. They are not known outside the procedure or function.

•	Procedures and functions can use global variables from the script, as long as the procedures and functions come after the global variable declarations.

•	Any time you want to modify the value of a parameter to a procedure or function, you must use the reserved word 'var' in front of the variable declaration in the parameter list.

Procedures

Functions


Procedures

procedure ProcName[(parameter list)];

[ var section ]

begin

end;

As an example on writing procedures, let's revisit the script from the help on the if statement, this time rewritten to use a procedure.

var Age: Integer;

    AgeStr: String;

    IsValid: Boolean;

procedure IsValidInt(Str:String; var IsValid:Boolean);

var Loop: Integer;

    AgeChar: Char;

begin

  IsValid:=True;

  if (Str='') then Result:=False

  else

    for Loop:=1 to Length(AgeStr) do

    begin

      AgeChar:=Copy(AgeStr,Loop,1);

      // Check to make sure each char is a valid number

      if (AgeChar<'0') or (AgeChar>'9') then

        IsValid:=False;

    end;

end;

begin

  repeat

    AgeStr:=InputBox('Getting age','Please enter your age','');

    IsValidInt(AgeStr,IsValid);

    if (not IsValid) then

      ShowMessage('Sorry, '+AgeStr+

                  ' is not a valid number. Please try again.');

  until (IsValid) or (AgeStr='');

  if (AgeStr='') then AgeStr:=0;

  Age:=StrToInt(AgeStr);

  if (Age<21) then ShowMessage('Still a kid.')

  else if (Age<40) then ShowMessage('Wet behind the ears')

  else if (Age<65) then ShowMessage('Middle aged')

  else ShowMessage('Would you like a 10% discount?');

end;


Functions

function FuncName[(parameter list)]: ResultType;

[var section]

begin

end;

Functions are like procedures, except they can have a return value. The type of the return value is spceified by the ResultType. To set the return value for a function, use Result. Let's revisit the script from the help on the if statement, this time rewritten with functions.

var Age: Integer;

    AgeStr: String;

    IsValid: Boolean;

function IsValidInt(Str:String): Boolean;

var Loop: Integer;

    AgeChar: Char;

begin

  Result:=True;

  if (Str='') then Result:=False

  else

    for Loop:=1 to Length(AgeStr) do

    begin

      AgeChar:=Copy(AgeStr,Loop,1);

      // Check to make sure each char is a valid number

      if (AgeChar<'0') or (AgeChar>'9') then

        Result:=False;

    end;

end;

begin

  repeat

    AgeStr:=InputBox('Getting age','Please enter your age','');

    IsValid:=IsValidInt(AgeStr);

    if (not IsValid) then

      ShowMessage('Sorry, '+AgeStr+

                  ' is not a valid number. Please try again.');

  until (IsValid) or (AgeStr='');

  if (AgeStr='') then AgeStr:=0;

  Age:=StrToInt(AgeStr);

  if (Age<21) then ShowMessage('Still a kid.')

  else if (Age<40) then ShowMessage('Wet behind the ears')

  else if (Age<65) then ShowMessage('Middle aged')

  else ShowMessage('Would you like a 10% discount?');

end;


Controlling J-Term Pro

J-Term Pro scripting provides many procedures and functions you can use to control the behavior of the program. These routines are listed by category below. Click on any category to get a list of the procedures and functions available in that category.

Connections

FTP in scripts

Database storage routines

Running scripts and programs

Firing an event

Using the system timer

Handling connection errors

Watches

Toolbars, buttons, and list windows

Playing sounds

Directories

Controlling the J-Term Pro main window


Connections

OpenConnection

CloseConnection

ActiveConnection

ClosePage

ActivePage

SetActivePage

SendLine

SendText

ConnectionName

CloseAllConnections

HostName

CloseProgram


OpenConnection

function OpenConnection(ConnectionName: String): Integer;

Opens a new connection to remote host. The ConnectionName parameter must be a valid connection name as defined in the Connection Manager. The return value of this function is the page number that J-Term Pro gives the new connection. Page numbers are zero-based, meaning the first open connection gets page 0, the second gets page 1, etc.

var PN: Integer;

begin

  // Open the connection named 'InterNIC'

  PN:=OpenConnection('InterNIC');

end;


CloseConnection

procedure CloseConnection(ConnectionName: String);

Closes the first open connection in the connection pages that has a name that matches the name in the ConnectionName parameter. See the help for OpenConnection for a cross reference.

begin

  // Close the connection named 'InterNIC'

  CloseConnection('InterNIC');

end;


ActiveConnection

function ActiveConnection: String;

Returns the name of the currently active connection in J-Term Pro.

begin

  ShowMessage('The current active connection is '+ActiveConnection);

end;


ClosePage

procedure ClosePage(PageNo: :Integer);

Closes page number PageNo in J-Term Pro.

begin

  ClosePage(ActivePage);

end;


ActivePage

function ActivePage: Integer;

Returns the page number of the currently active page in J-Term Pro. Page numbers are zero-based, meaning the first page is page 0, the second is page 1, and so on.

begin

  ShowMessage('The active page is '+IntToStr(ActivePage));

end;


SetActivePage

procedure  SetActivePage(PageNo: Integer);

Sets the current active page to PageNo

begin

  // Set the active page to the second connection

  SetActivePage(1);

end;


SendLine

procedure SendLine(PageNo: Integer; Text: String);

Sends the sequence of characters in Text to the connection specified by PageNo, followed by a carriage-return, as though you had typed the line.

begin

  // Get a file listing on the active page

  SendLine(ActivePage,'ls -l');

end;


SendText

procedure SendText(PageNo: Integer; Text: String);

Sends the sequence of characters in Text to the connection specified by PageNo, as though you had typed them.

begin

  // Send ls -al, but wait for user to actually hit enter

  SendText(ActivePage,'ls -l');

end;


ConnectionName

function ConnectionName: String;

Returns the name of the last connection opened, whether it is the active connection or not.

begin

  ShowMessage('The last connection opened was '+ConnectionName);

end;


CloseAllConnections

Should be self-evident.

begin

  // Close all connections and re-open the connection

  // named 'InterNIC'

  CloseAllConnections;

  OpenConnection('InterNIC');

end;


HostName

function HostName(ConnectionName:String): String;

This function returns the DNS host name or IP address of the given connection name.

begin

  ShowMessage('The host name of the current connection is '+

              HostName(ActiveConnection));

end;


LocalAddr

function LocalAddr: String;

The LocalAddr function returns your PC's local IP address as a string. This can be very useful for running applications on the remote host which need such information.

begin

  SendText(ActivePage,LocalAddr);

end;


CloseProgram

procedure CloseProgram;

Exits J-Term Pro, closing all open connections.

begin

  CloseProgram;

end;


FTP in scripts

J-Term Pro scripting has many routines for performing file transfers within scripts. Click on the routine below to find out more about it.

FTPConnect

FTPDisconnect

FTPBinary

FTPAscii

FTPSend

FTPReceive

Sample FTP script


FTPConnect

function FTPConnect(HostName, UserName, Password: String): Boolean;

This function opens an FTP connection to the given host, using the account specified in UserName/Password. It returns a true on successful connection, or a false if it was unable to connect. See the Sample FTP Script for an example showing the use of the FTP scripting commands.


FTPDisconnect

function FTPDisconnect: Boolean;

This function disconnects the current FTP connection opened with FTPConnect. It returns a true on a successful disconnect, or a false if the disconnect failed. See the Sample FTP Script for an example showing the use of the FTP scripting commands.


FTPBinary

procedure FTPBinary;

This procedure sets the FTP transfer mode to binary mode. See the Sample FTP Script for an example showing the use of the FTP scripting commands.


FTPAscii

procedure FTPAscii;

This procedure sets the FTP transfer mode to ASCII mode. See the Sample FTP Script for an example showing the use of the FTP scripting commands.


FTPSend

function FTPSend(LocalFile, RemoteFile:String): Boolean;

This function sends the file specified by LocalFile to the remote host. The file is sent to the location specified by RemoteFile. The function returns a true if the file was successfully sent, or a false it if was not. See the Sample FTP Script for an example showing the use of the FTP scripting commands.


FTPReceive

function FTPReceive(LocalFile, RemoteFile: String): Boolean;

This function retrieves the file specified by RemoteFile and places it on the local machine in the location specified in LocalFile. The function returns a true if the file was successfully received, or a false if it was not. See the Sample FTP Script for an example showing the use of the FTP scripting commands.


Sample FTP Script

The following script can be added to the J-Term Pro add-ins to provide local file editing, for those who don't like vi J. This script shows the use of the various FTP routines available to you.

var FileName: String;

    UserName, Password: String;

    Host: String;

function RetrieveFile(FileName,UserName,Password:String): Boolean;

begin

  if (FTPConnect(Host,UserName,Password)) then

  begin

    FTPAscii;

    if (FTPReceive('C:\TMP.TXT',FileName)) then

    begin

      FTPDisconnect;

      Result:=True;

    end

    else Result:=False;

  end

  else Result:=False;

end;

procedure EditFile;

begin

  ClearStatus;

  ExecuteFileWithWait('NOTEPAD.EXE','C:\TMP.TXT',SW_SHOWNORMAL);

end;

function ReturnFile(FileName,UserName,Password:String): Boolean;

begin

  if (FTPConnect(Host,UserName,Password)) then

  begin

    FTPAscii;

    if (FTPSend('C:\TMP.TXT',FileName)) then

    begin

      FTPDisconnect;

      Result:=True;

    end

    else Result:=False;

  end

  else Result:=False;

end;

begin

  FileName:=InputBox('Enter full path to file','Enter remote file name to edit','');

  if (FileName<>'') then

  begin

    Host:=HostName(ActiveConnection);

    GetUserPass(UserName,Password,'FTP account info');

    if (RetrieveFile(FileName,UserName,Password)) then

    begin

      EditFile;

      ReturnFile(FileName,UserName,Password);

    end;

  end;

end;


Database Storage Routines

J-Term Pro provides some limited database-type storage routines for saving variables and data across scripts. Though the data is not stored in an INI file, the same principle is used. Imagine the data being stored like this:

[SectionName]

Key1=Value1

Key2=Value2

[AnotherSection]

Key1=Value1

Key2=Value2

The following database storage routines are available:

SetValue

GetValue

DeleteValue

DeleteAllValues


SetValue

procedure SetValue(Section,Key,Value: String);

This procedure is used to store data values in a local database. Value is stored associated with Key under Section.

begin

// Set initial stuff here, run once

  SetValue('Command','NumRecs','4');

  SetValue('Command','Record1','whois do full quarknet.com');

  SetValue('Command','Record2','whois do full uu.net');

  SetValue('Command','Record3','whois do full jonesautomation.com');

  SetValue('Command','Record4','whois do full esig.com');

end;


GetValue

function GetValue(Section,Key: String): String;

This function retrieves  the specified value from the local database.

var Counter, ConnName: String;

begin

  { Get the stored counter value we're on }

  Counter:=GetValue('InterNIC','Counter');

  { Get the associated connection name }

  ConnName:=GetValue('InterNIC',Counter);

  { Store counters for the ' *' and 'ig>' prompts }

  SetValue(ConnName,'Counter1','1');

  SetValue(ConnName,'Counter2','1');

  { Here we go! }

  OpenConnection(ConnName);

  OnNetworkError(ActivePage,'C:\TMP\BOMERROR.JTS');

end;


DeleteValue

procedure DeleteValue(Section,Key: String): String;

This procedure removes an entry from the local database.

begin

  DeleteValue('InterNIC','Command1');

  DeleteValue('InterNIC','Counter');

end;


DeleteAllValues

procedure DeleteAllValues;

This procedure deletes all the stored values from the interal J-Term Pro database. Use this routine carefully.

begin

  DeleteAllValues;

end;


Running Scripts and Programs

RunScript

ExecuteFile

ExecuteFileWithWait


RunScript

procedure RunScript(ScriptName: String);

This procedure executes the script specified in the ScriptName parameter. The parameter must have the exact script name, including the extension, if there is one. It may be a good idea to specify the full path to the script, too.


ExecuteFile

function ExecuteFile(FileName, Params, StartDir: String;

                     Style: Integer): Integer;

This function runs the file specified by FileName, using the command line parameters specified in Params. The file is started in the directory specified my StartDir, and the initial program window is opened with the style set in the Style parameter. Valid values for Style are: SW_SHOWNORMAL, SW_SHOWMAXIMIZED,  and SW_SHOWMINIMIZED. If the file cannot be run for some reason, the function returns a value less than 32, otherwise it returns a positive integer.


ExecuteFileWithWait

function ExecuteFileWithWait(FileName,Params:String;

                             Style:Integer): Boolean;

This function runs the file specified by FileName, using the command line parameters specified in Params. The file is started in the directory specified my StartDir, and the initial program window is opened with the style set in the Style parameter. Valid values for Style are: SW_SHOWNORMAL, SW_SHOWMAXIMIZED,  and SW_SHOWMINIMIZED. The function does not return until the program file executed is closed. The function returns True if all went well, or False if the specified program could not be run.


GlobalEvent

procedure GlobalEvent(EventNo: Integer);

This procedure causes a global event to fire, thus executing any code associated with that event. Valid values for EventNo are: OnBeforeConnect, OnConnect, OnStart, OnStop, OnWatch, and OnDisconnect. If you override an event for a connection, and want the global event to fire after the connection event, use this procedure, or the global event will never get called.


Using the System Timer

The system timer can be used in a J-Term Pro script to force a delay in the code, or to cause an action to occur at a later time.

SetTimer

ClearTimer

Sleep


SetTimer

procedure SetTimer(NumSecs: Integer; ScriptToRun:String);

This procedure sets the system timer to fire in NumSecs seconds. When the timer fires, the script in the file name specified by ScriptToRun is executed.


Sleep

procedure Sleep(NumSecs:Integer);

The Sleep procedure is used to suspend the operation of J-Term Pro for the number of seconds specified in the NumSecs parameter.


ClearTimer

procedure ClearTimer;

This procedure is used to clear (or disable) the sytem timer started with a call to SetTimer.


OnNetworkError

procedure OnNetworkError(PageNo: Integer; ScriptToRun:String);

This procedure sets the script to run should the connection in PageNo receive a network connection error. PageNo is an integer representing one of the open pages (connections) in J-Term Pro. PageNo is a zero-based number. Should a network error occur in the connection, ScriptToRun will be executed.


Watches

J-Term Pro scripting provides many ways to use a script to interact with a telnet session. One such way is to use watches. J-Term Pro has a watch list at the global level, and each connection also has a watch list. A watch list is a list of text J-Term Pro is watching for to come across a telnet connection. When text matching text in a watch list is seen, one of the following things can happen:

•	A global OnWatch event can be fired

•	A connection-level OnWatch event can be fired

•	A script can be run

The following functions and procedures are used to deal with watches in J-Term Pro.

WatchText

AddWatch

AddGlobalWatch

AddWatchScript

AddGlobalWatchScript

ClearWatches

ClearGlobalWatches

RemoveWatch

RemoveGlobalWatch

Sample scripts to demonstrate watches


WatchText

function WatchText: String;

Returns the text of the last watch seen.


AddWatch

procedure AddWatch(WatchText: String; NumOccurrences: Integer);

This procedure adds a 'watch' for the text specified in the WatchText parameter to the active connection's watch list. When the specified text comes across the connection, the OnWatch event for that connection is fired, if the event is enabled. If the event is not enabled, the global OnWatch event is fired. The event will continue to fire until the WatchText has been seen NumOccurrences times. For example, set NumOccurrences to 1 if you only want to catch the text once.


AddGlobalWatch

procedure AddGlobalWatch(WatchText: String; NumOccurences: Integer);

Similar to the AddWatch procedure, but sets the watch at a global level. Any new connections that are created will also have the watch set.


AddWatchScript

procedure AddWatchScript(WatchText: String; NumOccurrences: Integer;

                         ScriptName: String);

Similar to the AddWatch procedure, but the script specified in ScriptName is run when the watch text is seen, instead of the OnWatch event being fired.


AddGlobalWatchScript

procedure AddGlobalWatchScript(WatchText: String;

                               NumOccurrences: Integer;

                               ScriptName: String);

Similar to the AddWatchScript procedure, but sets the watch at a global level. Any new connections that are created will also have the watch set.


ClearWatches

procedure ClearWatches(PageNo: Integer);

Empties the watch list for the specified page. Use the RemoveWatch procedure to remove a specific watch.


ClearGlobalWatches

procedure ClearGlobalWatches;

Empties the global watch list. Note: any connection that has had a watch set via a global watch will still have the watch set. Use the RemoveWatch procedure to clear out a specific watch.


RemoveWatch

procedure RemoveWatch(PageNo: Integer; WatchText: String);

Removes the watch specified by WatchText from the watch list of the connection specified by PageNo.


RemoveGlobalWatch

procedure RemoveGlobalWatch(WatchText: String);

Removes the global watch specified by WatchText. Any open connections that have had this watch set will retain the watch.


Sample Scripts Using Watches

Auto-login script

Capturing an InterNIC 'whois' session


Auto-login script

Making J-Term automatically login for you when you open connections is not a difficult matter, especially if you write the scripts as event handlers. Make sure you enable the handler, or it will not run. Enable handlers by checking the 'Enabled' box at the bottom of the event editor. Here is one way to create auto-logins:

// Global OnStart event script

// ---------------------------------------

// This script tells J-Term Pro to look for

// the login and password prompts one time

// for each connection that is opened.

begin

  AddGlobalWatch('ogin:',1);

  AddGlobalWatch('assword:',1);

end;

-----------------------------------------------------

// Global OnBeforeConnect event script

var UserName, Password: String;

begin

  // Load the stored user name and password

  UserName:=GetValue(ActiveConnection,'UserName');

  Password:=GetValue(ActiveConnection,'Password');

  // See if we need to prompt the user

  if (UserName='') or (Password='') then

  begin

    GetUserPass(UserName,Password,

                'Enter info for '+ActiveConnection);

    // Store the user name and password by connection

    SetValue(ActiveConnection,'UserName',UserName);

    SetValue(ActiveConnection,'Password',Password);

  end;

end;

-------------------------------------------------------

// Global OnWatch event script

var UserName, Password: String;

procedure SendUserName(UN:String);

// Send user name to active page

begin

  SendLine(ActivePage,UN);

end;

procedure SendPassword(PW:String);

// Send password to active page

begin

  SendLine(ActivePage,PW);

end;

begin

  if (WatchText='ogin:') then

    SendUserName(GetValue(ActiveConnection,'UserName'))

  else if (WatchText='assword:') then

    SendPassword(GetValue(ActiveConnection,'Password'));

end;


Capturing an InterNIC 'whois' session via scripts

The goal of these scripts is to demonstrate the power of J-Term Pro scripting, while also showing the usage of several of the scripting routines. These scripts will allow you to connect to internic.net, and perform several 'whois' commands, to get information about particular domains. When all of the whois commands are finished, the captured session data will be displayed in notepad.

The first thing we need is a script to set all the initial values we want to use across this set of scripts.

// SetVals.jts - this script sets up all the information our

// other scripts will need. We're setting 'NumRecs' to 4, because

// we want to do 4 'whois' commands.

// The 'Record' values are the actual whois commands. Note that

// 'Record' is followed by a number, 1 to NumRecs. We can use

// this to 'loop' across scripts, because we'll store a counter

// value later, and increment it each time we do a whois command.

begin

// Set initial stuff here, and run once

// You need to write a DelVals.jts to remove these from the db

  SetValue('Command','NumRecs','4');

  SetValue('Command','Record1','whois do full quarknet.com');

  SetValue('Command','Record2','whois do full uu.net');

  SetValue('Command','Record3','whois do full jonesautomation.com');

  SetValue('Command','Record4','whois do full esig.com');

end;

----------------------------------------------------

Next, we need a script to 'start the ball rolling', so to speak.

// Startup.jts - this script assumes that you have a connection

// named 'internic.net'. Use J-Term Pro to create such a connection

// and use the host name 'internic.net', also. That's the InterNIC's

// global 'whois' system.

begin

// Set the initial counter to 1 and open the first connection

%  SetValue('Command','Current','1');

  OpenConnection('internic.net');

// The first prompt we get from InterNIC is "InterNIC >". We want to

// watch for this one time, and run 'Watcher.jts' when we see the

// prompt

  AddWatchScript('NIC >',1,'Watcher.jts');

end;

---------------------------------------------------------

The next script will do the bulk of the work. It gets fired when our watches come across the connection. The first time this script fires is when 'NIC >' (set in the previous script) comes across the connection.

// Watcher.jts - This script is fired whenever any of our watches

// are spotted. Here's the logic of this function:

//    - Fire when 'NIC >' is seen (set in Startup.jts)

//    - When 'NIC >' fires, turn on file logging to save the

//      incoming data to a file, and set a watch to look for

//      'hois:' NumRecs+1 times (remember, NumRecs was set in

//      SetVals.jts). Once you do your first whois to InterNIC,

//      you get a 'whois:' prompt instead of an 'InterNIC >'

//      prompt. That's why we're looking for 'hois:' from now

//      on.

//    - Each time we see a 'hois:' prompt, send the next whois

//      command (based on 'Current')

//    - When we've sent all our whois commands, turn off file

//      logging and close the connection.

//    - Kick off notepad with the log we saved.

procedure SendFirst;

// Send the response to 'NIC >'

// Then set enough watches to catch all the 'hois:' prompts

// Note that we watch for NumRecs+1 'hois:' prompts

// Also turn logging on

// At the end of the routine, increment the counter

begin

  StartFileLog(ActivePage,'C:\TMP\FRED.LOG');

  // Add NumRecs+1 watches for 'hois:'. Each time we see this watch,

  // fire this same script again.

  AddWatchScript('hois:',StrToInt(GetValue('Command','NumRecs'))+1,'Watcher.jts');

  SendText(ActivePage,GetValue('Command','Record'+GetValue('Command','Current'))+#10);

  SetValue('Command','Current',IntToStr(StrToInt(GetValue('Command','Current'))+1));

end;

procedure SendNext;

// If we're looking at the NumRecs+1 'hois:' prompt, we're done

// otherwise, send the next whois command and inc the counter.

begin

  if (GetValue('Command','Current')=IntToStr(StrToInt(GetValue('Command','NumRecs'))+1)) then

  begin

    StopFileLog(ActivePage);

    ClosePage(ActivePage);

    ExecuteFile('NOTEPAD.EXE','C:\TMP\FRED.LOG','',SW_SHOWNORMAL);

  end

  else

  begin

    SendLine(ActivePage,GetValue('Command','Record'+GetValue('Command','Current')));

    SetValue('Command','Current',IntToStr(StrToInt(GetValue('Command','Current'))+1));

  end;

end;

// The main routine is simple. Remember, this script will be fired

// several times, because of the watches.

begin

  if (WatchText='NIC >') then SendFirst

  else if (WatchText='hois:') then SendNext;

end;


Playing sounds

J-Term Pro provides two routines for playing multimedia sounds. Normally, one wouldn't think of a reason to play sounds in a telnet session, but sounds can be used to give feedback. Use them to let you know when a background task is done, perhaps.

PlayWAVFile

PlayMIDIFile


PlayWAVFile

procedure PlayWAVFile(FileName:String);

The PlayWAVFile procedure is used to play a standard Windows WAV file. The FileName passed to the procedure must have a .WAV extension, or the file will not be played.

begin

  // Play a WAV of Fred singing 'The Lion Sleeps Tonight' acappella

  // Email jtermpro@jonesautomation.com if you'd like this file :)

  PlayWAVFile('E:\MIRC\SOUNDS\LION.WAV');

end;


PlayMIDIFile

procedure PlayMIDIFile(FileName:String);

The PlayMIDIFile procedure is used to play a standard Windows MIDI file. The FileName passed to the procedure must have a .MID extension, or the file will not be played.

begin

  // Play a MIDI FILE

  PlayMIDIFile('E:\MIRC\SOUNDS\LION.MID');

end;


Toolbars, buttons, and list windows

J-Term Pro has many routines for working with toolbars, windows, and buttons. Click on the routine you'd like to know more about.

Toolbar functions

The following routines are for manipulating the user-configurable toolbar in J-Term Pro.

HideToolbar

ShowToolbar

HideUserToolbar

ShowUserToolbar

Button functions

These routines are for manipulating buttons on the user-configurable toolbar

AddToolbarButton

RemoveToolbarButton

SetToolbarButtonText

SetToolbarButtonGlyph

AddToolbarSpacer

RemoveToolbarSpacer

Scripts to show the use of buttons

List window functions

These routines are for creating and using list windows in J-Term Pro. List windows are windows that provide a list of values, and allow the user to select one of the values.

CreateListWindow

DeleteListWindow

AddListWindowItem

DeleteListWindowItem

ShowListWindow

GetListWindowItem


Scripts to Show the Use of Toolbars and Buttons

// AddButtons.jts - This script adds buttons to the user toolbar

// to kick off the FTP client or server program.

// To always have these programs around, attach this code into

// your global OnStart event.

var Btn: Integer;

begin

  ShowUserToolbar;

  Btn:=AddToolbarButton(100,'Start FTP Client','FTPClient.jts');

  SetToolbarButtonText(Btn,'FTP Client');

  Btn:=AddToolbarButton(100,'Start FTP Server','FTPServer.jts');

  SetToolbarButtonText(Btn,'FTP Server');

end;

--------------------------------------------------------------

// FTPClient.jts - This script executes the FTP client program

begin

  ExecuteFile(InstallDir+'JTPFTP.EXE','','',SW_SHOWNORMAL);

end;

--------------------------------------------------------------

// FTPServer.jts - This script executes the FTP server program

begin

  ExecuteFile(InstallDir+'JTFTPSRV.EXE','','',SW_SHOWNORMAL);

end;


HideToolbar

procedure HideToolbar;

This procedure hides the standard toolbar, the same way that unchecking 'Show button bar' on the 'Edit' menu does.


ShowToolbar

procedure ShowToolbar;

This procedure shows the standard toolbar, the same way that checking 'Show button bar' on the 'Edit' menu does.


HideUserToolbar

procedure HideUserToolbar;

This procedure hides the user-configurable toolbar.


ShowUserToolbar

procedure ShowUserToolbar;

This procedure Shows the user-configurable toolbar.


AddToolbarButton

function AddToolbarButton(Width:Integer; Hint,Script:String): Integer;

This function creates a new, blank button Width pixels wide on the user configurable toolbar. Hint is the popup text shown when the mouse pointer sit over the button for about a second. Script is the script to be run when the button is clicked. The function returns an integer identifier for the button which can be used as the ButtonID paramater to the other button manipulation routines.

See the sample button script for an example of this function.


RemoveToolbarButton

procedure RemoveToolbarButton(ButtonID:Integer);

This procedure removes a button (specified by ButtonID) previously created on the user-configurable toolbar with the AddToolbarButton function.


SetToolbarButtonText

procedure SetToolbarButtonText(ButtonID:Integer; Text:String);

This procedure sets the text for the button identified by ButtonID. For an example of this procedure call, click here.


SetToolbarButtonGlyph

procedure SetToolbarButtonGlyph(ButtonID:Integer; Filename:String);

This procedure sets the glyph (picture)  for the button identified by ButtonID. Filename must point to a valid Windows bitmap (.BMP) file.


AddToolbarSpacer

function AddToolbarSpacer: Integer;

This function creates a separator on the user-configurable toolbar, allowing for space between buttons to provide for logical grouping. The function returns an integer identifier for the separator that can be used as the SpacerID for the RemoveToolbarSpacer procedure.


RemoveToolbarSpacer

procedure RemoveToolbarSpacer(SpacerID:Integer);

This function removes a separator previously created by a call to AddToolbarSpacer from the user-configurable toolbar. SpacerID is an integer identifier for a spacer returned by the call to AddToolbarSpacer.


Directories

J-Term Pro provides several routines for dealing with directories on your local hard drives. Click on a routine to find out more about it.

CurrentDir

ChangeDir

InstallDir


CurrentDir

function CurrentDir: String;

The CurrentDir function returns the current active directory.

begin

  ShowMessage('The current directory is: '+CurrentDir);

  ChangeDir('C:\');

  ShowMessage('The current directory is now: '+CurrentDir);

end;


InstallDir

function InstallDir: String;

The InstallDir function returns the directory where J-Term Pro is installed. For installations where the default was taken, this is C:\PROGRAM FILES\JAI\J-TERM PRO.

begin

  ExecuteFile(InstallDir+'JTERMPRO.EXE','',InstallDir,SW_SHOWNORMAL);

end;


ChangeDir

function ChDir(NewDir:String): Boolean;

The ChDir function changes directories to the directory specified, returning True if the operation is successful, or false otherwise.

begin

  // Change to J-Term Pro home directory

  ChangeDir(InstallDir);

  // Execute J-Term Pro

  ExecuteFile('JTERMPRO.EXE','','',SW_SHOWNORMAL);

end;


Sample Scripts

The following sample scripts are provided to help you better learn the J-Term Pro scripting language.

Auto-login script

Local file edit script

Capturing an InterNIC 'whois' session via scripts

Scripts to Show the Use of Toolbars and Buttons

Script showing the use of list windows


CreateListWindow

function CreateListWindow(Caption,Label:String): Integer;

The CreateListWindow creates an empty list window. A list window is a system window which contains a list of values from which the user can make a selection. The list window also has Windows standard 'Ok' and 'Cancel' buttons. Upon creation, the list window has not items in the list box. The return value of this function is an integer which uniquely identifies the window, and can be used as the ListWin parameter for the other list window routines. For an example using this and the other list window routines, see the help section entitled 'Script showing the use of list windows'.


DeleteListWindow

procedure DeleteListWindow(ListWin:Integer);

This procedure destroys the list window (previously created with a call to CreateListWindow) specified by the ListWind parameter. For an example using this and the other list window routines, see the help section entitled 'Script showing the use of list windows'.


AddListWindowItem

function AddListWindowItem(ListWin:Integer; Item:String): Integer;

This procedure adds a new selection item to the list box in the list window specified by the ListWin parameter. The new selection item is added to the end of the list, and contains the text specified by the Item parameter. The return value of the function is the zero-based index number of the Item in the list. The first call to AddListWindowItem for a particular list window will return a 0, the second 1, the third 2, etc. For an example using this and the other list window routines, see the help section entitled 'Script showing the use of list windows'.


DeleteListWindowItem

procedure DeleteListWindowItem(ListWin:Integer; Index:Integer);

This procedure removes the item at position Index from the list window referenced by the ListWin parameter. Index should be a zero-based number, so if you want to delete the third item in a list, pass an Index of 2. For an example using this and the other list window routines, see the help section entitled 'Script showing the use of list windows'.


ShowListWindow

function ShowListWindow(ListWin:Integer): Integer;

This function displays the list window spcified by ListWin and waits for the user to select an item from the list box. The function returns the zero-based index of the item selected, or a -1 if the user closes the list box without choosing an item. For an example using this and the other list window routines, see the help section entitled 'Script showing the use of list windows'.


GetListWindowItem

function GetListWindowItem(ListWin:Integer; Index:Integer): String;

This function returns the string text of the item at zero-based position Index in the list window referenced by the ListWin parameter. For an example using this and the other list window routines, see the help section entitled 'Script showing the use of list windows'.


Script showing the use of list windows

The following script is used to show the use of list windows for interacting with users in J-Term Pro.

// ListWin.jts - Shows the use of list windows

var LW: Integer;

// Build the list window in this procedure

procedure BuildListWindow(var Handle:Integer);

begin

  Handle:=CreateListWindow('Simple unix functions','Select a function');

  AddListWindowItem(Handle,'Directory listing (short)');

  AddListWindowItem(Handle,'Directory listing (long)');

  AddListWindowItem(Handle,'Edit a file with vi');

  AddListWindowItem(Handle,'Process status');

end;

// This procedure is to process the selection made by the user

procedure ProcessInput(Item:Integer);

var FileName: String;

begin

  if Item=0 then SendLine(ActivePage,'ls')

  else if Item=1 then SendLine(ActivePage,'ls -al')

  else if Item=2 then

  begin

    FileName:=InputBox('Enter name of file to edit','File name','.login');

SendLine(ActivePage,'vi '+FileName);

  end

  else if Item=3 then SendLine(ActivePage,'ps -aux');

end;

begin

  // Create the window

  BuildListWindow(LW);

  // Handle user interaction

  ProcessInput(ShowListWindow(LW));

  // Free the memory for the list window

  DeleteListWindow(LW);

end;


Controlling the J-Term Pro main window

J-Term Pro scripting provides the following routines for controlling the main application window.

Maximize

Minimize

Restore


Maximize

procedure Maximize;

This procedure forces the J-Term Pro main window to maximize, filling up the entire desktop.


Minimize

procedure Minimize;

This procedure minimizes the main J-Term Pro window on the desktop.


Restore

procedure Restore;

This procedure restores the J-Term Pro main window to it's original size from a maximized or minimized state.


ShowMessageWindow

procedure ShowMessageWindow(Caption, Message: String);

This procedure shows the J-Term Pro message window with the specified caption and message. The message window can only be closed with a call to HideMessageWindow.


HideMessageWindow

procedure HideMessageWindow;

This procedure hides the J-Term Pro message window.


SetMessageWindowText

procedure SetMessageWindowText(Caption,Message:String);

This procedure changes the the caption and message in the J-Term Pro message window. This procedure can be called to change these values while the message window is being displayed.